cc.FileUtils:getInstance():setPopupNotify(false)

cc.FileUtils:getInstance():addSearchPath("client/src/")
cc.FileUtils:getInstance():addSearchPath("client/res/")

cc.FileUtils:getInstance():addSearchPath("base/src/")
cc.FileUtils:getInstance():addSearchPath("base/res/")

-- cc.FileUtils:getInstance():addSearchPath("download/")


local breakInfoFun,xpCallFun = require("LuaDebug")("localhost", 7005)
cc.Director:getInstance():getScheduler():scheduleScriptFunc(breakInfoFun, 0.3, false)
function __G__TRACKBACK__(errorMessage)
    print("----------------------------------------")
    print("LUA ERROR: " .. tostring(errorMessage) .. "\n")
    print(debug.traceback("", 2))
    buglyReportLuaException(errorMessage, debug.traceback())
   -- postError(tostring(errorMessage))
    breakInfoFun()
    print("----------------------------------------")
end



cc.FileUtils:getInstance():addSearchPath(cc.FileUtils:getInstance():getWritablePath().."baseupdate/",true)


require "config"
require "cocos.init"


local function main()

   local myapp = require("app.MyApp"):create()
  
   local package_ver = cc.Application:getInstance():getVersion()
   local cur_package_ver =  cc.UserDefault:getInstance():getStringForKey("package_ver") or ""
   if package_ver ~= cur_package_ver then  ---重新安装 安装包  清除缓存

       local fileUtil = cc.FileUtils:getInstance()
       device.writablePath = cc.FileUtils:getInstance():getWritablePath()
       fileUtil:removeFile(device.writablePath.."config.txt")
       fileUtil:removeDirectory(device.writablePath.."baseupdate/")

       local isFileExit =  cc.FileUtils:getInstance():isFileExist("account.txt") 
       if not isFileExit then
            local account = cc.UserDefault:getInstance():getStringForKey("account")
            local pwd = cc.UserDefault:getInstance():getStringForKey("pwd")
            if account ~= "" then
                local accountinfo = {account=account,pwd=pwd,type=1}
                cc.FileUtils:getInstance():writeStringToFile(cjson.encode(accountinfo),device.writablePath .."account.txt");
            end
       end

        if device.platform ~= "windows" then
            fileUtil:removeFile(device.writablePath.."UserDefault.xml")
            fileUtil:removeFile(device.writablePath.."version.plist")
        end
       
       cc.UserDefault:getInstance():setStringForKey("package_ver", package_ver)
       cc.UserDefault:getInstance():flush()
       myapp._version =  require("app.models.Version"):create()

    end
    appdf.isTest = myapp._version:getIsTest()
    
    myapp:run()
end

local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
    print(msg)
end

-- nativeMessageBox = function( ... )
--     -- body
-- end
